<template>
	<view class="detail">
		<up-navbar :autoBack="true" bg-color="#00000000" left-icon-color="#fff" @click-left="handleBack" />
		<view class="d_con">
			<image :src="data.item.img" mode="aspectFill"></image>
			<view class="d_content">
				<view class="j_con">
					<view class="tit" style="display: flex;">
						<text style="margin-right: 7px;font-size: 17px">{{data.item.title}}</text>
						<up-tag text="5A级风景区" size="mini" shape="circle"></up-tag>
					</view>
					<view class="jj">
						<text style="font-weight: 700;font-size: 14px">
							景区介绍：
						</text>
						<text class="nr">
							{{data.item.introduce}}
						</text>
					</view>
					<view class="j_con">
						<view class="jj">
							<text style="font-weight: 700;font-size: 14px;">开放时间：</text>
							<text class="nr">{{data.item.times}}</text>
						</view>
					</view>
					<view class="j_con ls">
						<view class="tit" style="font-size: 34rpx;">
							游玩推荐
						</view>
						<view class="jj tj_list">
							<view class="item" v-for="(item,index) in data.list" :key="index" @click="goLine(item)">
								<image :src="item.url" mode="aspectFill"></image>
								<view class="toFixed">
									{{item.tag}}
								</view>
								<view class="infos">
									<view class="tit">
										{{item.title}}
									</view>
									<view class="desc">
										<up-icon name="map" color="#9c9c9c" size="16"></up-icon>
										<text class="text">{{item.desc}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app'

	import {
		reactive
	} from 'vue'
	import {
		getDetail
	} from '../../api/api.js'

	const data = reactive({
		item: {},
		list: []
	})

	onLoad((option) => {
		// 拿到传过来的详情页数据
		data.item = JSON.parse(decodeURIComponent(option.item))
		getDetail().then(res => {
			data.list = res
		})

	})

	// 返回事件处理函数
	const handleBack = () => {
		uni.navigateBack({
			delta: 1, // 返回层数
			fail: () => {
				// 如果无法返回，则跳转到首页
				uni.switchTab({
					url: '/pages/index/index'
				})
			}
		})
	}

	// 跳转到地图页
	const goLine = (item) => {
		// 导航到地图页
		uni.navigateTo({
			url: `/pages/line/line?id=${item.id}`
		})
	}
</script>

<style lang="scss">
	.detail {
		background-color: #f5f5f5;

		.d_con {
			image {
				width: 100%;
				height: 600rpx;
			}

			.d_content {
				width: 100%;
				height: 700rpx;
				margin-top: -40rpx;
				background-color: #fff;
				padding: 35rpx 30rpx;
				box-sizing: border-box;
				border-radius: 0 30rpx;
				position: relative;
				z-index: 9;
			}

			.j_con {
				margin-bottom: 30rpx;

				.tit {
					font-size: 36rpx;
					font-weight: 700;
					color: #111;
					margin-bottom: 30rpx;
				}

				.jj {
					.nr {
						font-size: 26rpx;
						color: #8a8a8a;
						line-height: 40rpx;
					}
				}

				.tj_list {
					display: flex;
					flex-wrap: wrap;
					justify-content: space-between;

					.item {
						position: relative;
						width: 48%;
						margin-bottom: 20rpx;
						box-shadow: 1px 2px 3px #e5e5e5;
						// border-radius: 0 20rpx;
						border-top-left-radius: 20rpx;
						border-top-right-radius: 20rpx;
						overflow: hidden;

						.toFixed {
							position: absolute;
							top: 0;
							left: 0;
							border-top-left-radius: 20rpx;
							border-bottom-right-radius: 20rpx;
							background-color: #ffaa7f;
							color: #fff;
							text-align: center;
							font-size: 22rpx;
							padding: 5rpx 20rpx;
							box-sizing: border-box;
						}

						image {
							width: 100%;
							height: 200rpx;
							border-radius: 20rpx 20rpx 0 0;
						}

						.infos {
							padding: 10rpx 15rpx;

							.tit {
								font-size: 28rpx;
								font-weight: 700;
								color: #111;
								margin-bottom: 15rpx;
								text-overflow: ellipsis;
							}

							.desc {
								display: flex;
								justify-content: flex-start;
								align-items: center;

								.text {
									font-size: 26rpx;
									color: #8a8a8a;
								}
							}
						}
					}
				}
			}
		}
	}
</style>